
// 播放歌曲代码单独存储位
const song = {
    state:{
        // 当前歌曲列表
        listOfSongs: [],
        isPlay: false,  // 是否播放
        url: '',        //歌曲地址
        id: '',        //歌曲id
        playButtonUrl: '#icon-bofang', //播放状态的图标
        duration: 0, //音乐时长
        curTime: 0, //当前音乐播放位置
        changeTime:0, //指定播放时刻
        title:'', //歌名
        artist: '', //歌手名字
        picUrl: '', //歌曲图片
        autoNext: true,//用于自动触发下一首播放
        lyric:[],//未处理的歌词数据
        templist:{},//单个歌单信息
        listIndex:null,//当前歌曲在歌单中的位置
        volum:50,//音量

    },
    getters:{
        listOfSongs: state =>{
            let listOfSongs = state.listOfSongs;
            if(!listOfSongs.length){
                listOfSongs =JSON.parse(window.sessionStorage.getItem('listOfSongs') || null);
            }
            return listOfSongs;
        },
        isPlay: state =>{
            let isPlay = state.isPlay;
            if(!isPlay){
                isPlay =JSON.parse(window.sessionStorage.getItem('isPlay') || null);
            }
            return isPlay;
        },
        url: state => {
            let url = state.url;
            if(!url){
                url =JSON.parse(window.sessionStorage.getItem('url') || null);
            }
            return url;
        },
        id: state => {
            let id = state.id;
            if(!id){
                id =JSON.parse(window.sessionStorage.getItem('id') || null);
            }
            return id;
        },
        playButtonUrl: state => {
            let playButtonUrl = state.playButtonUrl;
            if(!playButtonUrl){
                playButtonUrl =JSON.parse(window.sessionStorage.getItem('playButtonUrl') || null);
            }
            return playButtonUrl;
        },
        duration: state => {
            let duration = state.duration;
            if(!duration){
                duration =JSON.parse(window.sessionStorage.getItem('duration') || null);
            }
            return duration;
        },
        curTime: state => {
            let curTime = state.curTime;
            if(!curTime){
                curTime =JSON.parse(window.sessionStorage.getItem('curTime') || null);
            }
            return curTime;
        },
        changeTime: state => {
            let changeTime = state.changeTime;
            if(!changeTime){
                changeTime =JSON.parse(window.sessionStorage.getItem('changeTime') || null);
            }
            return changeTime;
        },
        title: state => {
            let title = state.title;
            if(!title){
                title =JSON.parse(window.sessionStorage.getItem('title') || null);
            }
            return title;
        },
        artist: state => {
            let artist = state.artist;
            if(!artist){
                artist =JSON.parse(window.sessionStorage.getItem('artist') || null);
            }
            return artist;
        },
        picUrl: state => {
            let picUrl = state.picUrl;
            if(!picUrl){
                picUrl =JSON.parse(window.sessionStorage.getItem('picUrl') || null);
            }
            return picUrl;
        },
        autoNext: state => {
            let autoNext = state.autoNext;
            if(!autoNext){
                autoNext =JSON.parse(window.sessionStorage.getItem('autoNext') || null);
            }
            return autoNext;
        },
        lyric: state => {
            let lyric = state.lyric;
            if(!lyric){
                lyric =JSON.parse(window.sessionStorage.getItem('lyric') || null);
            }
            return lyric;
        },
        templist: state => {
            let templist = state.templist;
            if(!templist){
                templist =JSON.parse(window.sessionStorage.getItem('templist') || null);
            }
            return templist;
        },
        listIndex: state => {
            let listIndex = state.listIndex;
            if(!listIndex){
                listIndex =JSON.parse(window.sessionStorage.getItem('listIndex') || null);
            }
            return listIndex;
        },
        volum: state => {
            let volum = state.volum;
            if(!volum){
                volum =JSON.parse(window.sessionStorage.getItem('volum') || null);
            }
            return volum;
        }
    },
    mutations:{
        setListOfSongs:(state,listOfSongs) => {
            state.listOfSongs = listOfSongs;
            window.sessionStorage.setItem('listOfSongs',JSON.stringify(listOfSongs));
        },
        setIsPlay :(state,isPlay) => {
            state.isPlay = isPlay;
            window.sessionStorage.setItem('isPlay',JSON.stringify(isPlay));

        },
        setUrl: (state,url) => {
            state.url = url;
            window.sessionStorage.setItem('url',JSON.stringify(url));

        },
        setId:  (state,id) => {
            state.id = id;
            window.sessionStorage.setItem('id',JSON.stringify(id));
        },
        setPlayButtonUrl:  (state,playButtonUrl) => {
            state.playButtonUrl = playButtonUrl;
            window.sessionStorage.setItem('playButtonUrl',JSON.stringify(playButtonUrl));
        },
        setDuration:  (state,duration) => {
            state.duration = duration;
            window.sessionStorage.setItem('duration',JSON.stringify(duration));
        },
        setCurTime:  (state,curTime) => {
            state.curTime = curTime;
            window.sessionStorage.setItem('curTime',JSON.stringify(curTime));
        },
        setChangeTime:  (state,changeTime) => {
            state.changeTime = changeTime;
            window.sessionStorage.setItem('changeTime',JSON.stringify(changeTime));
        },
        setTitle:  (state,title) => {
            state.title = title;
            window.sessionStorage.setItem('title',JSON.stringify(title));
        },
        setArtist:  (state,artist) => {
            state.artist = artist;
            window.sessionStorage.setItem('artist',JSON.stringify(artist));
        },
        setPicUrl:  (state,picUrl) => {
            state.picUrl = picUrl;
            window.sessionStorage.setItem('picUrl',JSON.stringify(picUrl));
        },
        setAutoNext:  (state,autoNext) => {
            state.autoNext = autoNext;
            window.sessionStorage.setItem('autoNext',JSON.stringify(autoNext));
        },
        setLyric:  (state,lyric) => {
            state.lyric = lyric;
            window.sessionStorage.setItem('lyric',JSON.stringify(lyric));
        },
        setTemplist:  (state,templist) => {
            state.templist = templist;
            window.sessionStorage.setItem('templist',JSON.stringify(templist));
        },
        setListIndex:  (state,listIndex) => {
            state.listIndex = listIndex;
            window.sessionStorage.setItem('listIndex',JSON.stringify(listIndex));
        },
        setVolum:  (state,volum) => {
            state.volum = volum;
            window.sessionStorage.setItem('volum',JSON.stringify(volum));
        }
    }
}



export default song